package com.insight.common.exception;

/**
 * T022: 元数据采集异常
 * 当元数据采集过程中发生错误时抛出
 */
public class MetadataCollectionException extends RuntimeException {

    /**
     * 数据源ID
     */
    private final Long datasourceId;

    /**
     * 数据源名称
     */
    private final String datasourceName;

    /**
     * 失败的表名（可选）
     */
    private final String tableName;

    public MetadataCollectionException(Long datasourceId, String datasourceName, String message) {
        super(String.format("Failed to collect metadata from datasource '%s' (ID: %d) - %s",
                datasourceName, datasourceId, message));
        this.datasourceId = datasourceId;
        this.datasourceName = datasourceName;
        this.tableName = null;
    }

    public MetadataCollectionException(Long datasourceId, String datasourceName, String tableName, String message) {
        super(String.format("Failed to collect metadata for table '%s' from datasource '%s' (ID: %d) - %s",
                tableName, datasourceName, datasourceId, message));
        this.datasourceId = datasourceId;
        this.datasourceName = datasourceName;
        this.tableName = tableName;
    }

    public MetadataCollectionException(Long datasourceId, String datasourceName, Throwable cause) {
        super(String.format("Failed to collect metadata from datasource '%s' (ID: %d)",
                datasourceName, datasourceId), cause);
        this.datasourceId = datasourceId;
        this.datasourceName = datasourceName;
        this.tableName = null;
    }

    public MetadataCollectionException(String message) {
        super(message);
        this.datasourceId = null;
        this.datasourceName = null;
        this.tableName = null;
    }

    public MetadataCollectionException(String message, Throwable cause) {
        super(message, cause);
        this.datasourceId = null;
        this.datasourceName = null;
        this.tableName = null;
    }

    public Long getDatasourceId() {
        return datasourceId;
    }

    public String getDatasourceName() {
        return datasourceName;
    }

    public String getTableName() {
        return tableName;
    }
}
